<layout name="../../Admin/View/master"/>
<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
    <li><a href="index.html"><i class="fa fa-home"></i> Home</a></li>
    <li><a href="#">UI kit</a></li>
    <li><a href="#">Form</a></li>
    <li class="active">Elements</li>
</ul>
<div class="m-b-md">
    <h3 class="m-b-none">商品修改</h3>
</div>
<div class="row">
    <div class="col-sm-12">
        <section class="panel panel-default">
            <header class="panel-heading font-bold">修改商品</header>
            <div class="panel-body">
                <form role="form" method="post" action="">
                    <div class="form-group">
                        <label>商品名称</label>
                        <input type="text" name='gname' value="{$olddata['gname']}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>商品编号</label>
                        <input type="text" name='number' value="{$olddata['number']}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>商品状态</label>
                        <div class="btn-group">
                            <if condition="$olddata['status'] eq 1">
                                <input type="hidden" name="status" value="{$olddata['status']}">
                                <button type="button" class="btn btn-success">已上架</button>
                                <else />
                                <input type="hidden" name="status" value="{$olddata['status']}">
                                <button type="button" class="btn btn-info">未上架</button>
                            </if>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>商品原价</label>
                        <input type="text" name='price' value="{$olddata['price']}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>商品促销价</label>
                        <input type="text" name='priced' value="{$olddata['priced']}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>商品排序</label>
                        <input type="text" name='sort' value="{$olddata['sort']}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>所属种类</label>
                        <select name="nid" id="inputID" class="form-control">
                            <option value=""> -- Select One --</option>
                            <foreach name="nature" item="vo">
                                <option value="{$vo['nid']}" <if condition="$olddata['nid'] eq $vo['nid']"> selected </if>>{$vo['nname']}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>所属分类</label>
                        <select name="cid"  class="form-control">
                            <option value="{$olddata['cid']}">{$olddata['cname']}</option>
                            <foreach name="category" item="vo">
                                <option value="{$vo['cid']}" >{$vo['cname']}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>所属品牌</label>
                        <select name="bid"  class="form-control">
                            <option value=""> -- Select One --</option>
                            <foreach name="brand" item="vo">
                                <option  value="{$vo['bid']}" <if condition="$olddata['bid'] eq $vo['bid']"> selected </if>>{$vo['bname']}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <p>商品简介</p>
                        <textarea name="digest"  cols="80" rows="5">{$olddata['digest']}</textarea>
                    </div>
                    <div class="form-group">
                        <p>商品特性</p>
                        <textarea name="style"  cols="80" rows="5" placeholder="商品特性|特性值">{$olddata['styled']}</textarea>
                    </div>

                    <li class="list-group-item">商品代表图:
                        <p style="padding: 5px 5px">
                            <img src="{$olddata['thumb']}" width="100px" style="margin-right: 10px" alt="">
                        </p>
                        <div>
                            <input type="file" name="file_upload" id="file_upload0">
                        </div>
                        <div id="upload0">
                            <input type="hidden" name="picaddr" value="{$olddata['thumb']}">
                        </div>
                    </li>

                    <script>
                        $(function() {
                            $("#file_upload0").uploadify({
                                height        : 30,
                                'removeTimeout' : 0.2,
                                swf           : '__PUBLIC__/uploadify/uploadify.swf',
                                uploader      : '{:U("goods/puc/pic")}',
                                width         : 120,
                                'uploadLimit' : 1,
                                'buttonText' : '请选择图片',
                                'onUploadSuccess' : function(file, data, response) {
                                    str ='<li><img src="'+data+'" alt="" height="50px" >';
                                    str+='<a href="javascript:;" class="delimg" path="'+data+'">X<a/>';
                                    str+='<input type="hidden" name="thumb" value="'+data+'"/>'
                                    str+='</li>';
                                    $('#upload0').append(str);
                                },
                            });
                        });
                    </script>
                    <script>
                        $(function(){
                            $('#upload0').on('click','.delimg',function(){
                                var path=$(this).attr('path');
                                that =$(this);
                                $.ajax({
                                    type: "POST",
                                    url: "{:u('goods/puc/delimg')}",
                                    data: {path:path},
                                    dataType: "json",
                                    success: function(msg){
                                        if(msg){
                                            that.parent('li').remove();
                                        }
                                    }
                                });
                            })
                        })
                    </script>

                    <div class="form-group">
                        <label>商品缩略图</label>
                        <ul>
                            <?php foreach($olddata['pic'] as $v){?>
                            <li style="margin-right: 10px;margin-bottom: 10px;display: inline-block" >
                                <img src="<?php echo $v?>" width="100px" alt="">
                                <input type="hidden" name="pic[]" value="<?php echo $v?>">
                                <span style="cursor: pointer;color: red;font-size: 20px" onclick="delimg(this,'<?php echo $v ?>')">X</span>
                            </li>
                            <?php }?>
                        </ul>
                        <input type="file" name="file_upload" id="file_upload1">
                        <div id="upload">

                        </div>
                    </div>

                    <script>
                        $(function() {
                            $("#file_upload1").uploadify({
                                height        : 30,
                                'removeTimeout' : 0.2,
                                swf           : '__PUBLIC__/uploadify/uploadify.swf',
                                uploader      : '{:U("goods/puc/pic")}',
                                width         : 120,
                                'buttonText' : '继续上传',
                                'onUploadSuccess' : function(file, data, response) {
                                    str ='<li><img src="'+data+'" alt="" height="50px" >';
                                    str+='<a href="javascript:;" class="delimg" path="'+data+'">X<a/>';
                                    str+='<input type="hidden" name="pic[]" value="'+data+'"/>'
                                    str+='</li>';
                                    $('#upload').append(str);
                                },
                            });
                        });
                    </script>
                    <script>
                        $(function(){
                            $('#upload').on('click','.delimg',function(){
                                var path=$(this).attr('path');
                                that =$(this);
                                $.ajax({
                                    type: "POST",
                                    url: "{:u('goods/puc/delimg')}",
                                    data: {path:path},
                                    dataType: "json",
                                    success: function(msg){
                                        if(msg){
                                            that.parent('li').remove();
                                        }
                                    }
                                });
                            })
                        })
                    </script>


                    <div class="form-group">
                        <div>商品详情</div>
                        <div>
                            <script id="editor" type="text/plain" style="width:1024px;height:500px;">{$olddata['content']}</script>
                        </div>
                    </div>

                    <div class="form-group">
                        <label>添加人</label>
                        <input value="{$olddata['adduser']}"  type="text" <if condition="isset($olddata['adduser'])"> readonly </if> name="adduser" class="form-control">
                    </div>
                    <button type="submit" class="btn btn-sm btn-success">提交</button>
                </form>
            </div>
        </section>
    </div>
</div>
<script>
    var ue = UE.getEditor('editor');
</script>
<script>
    function delimg(that,path){
        util.confirm('确定删除吗?',function(){
            $.ajax({
                type: "post",
                url: "{:U('goods/puc/delimg')}",
                dataType: "json",
                data: {path:path},
                success: function(msg){
                 $(that).parent('li').remove();
                }
            })
        })
    }
</script>



